<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Store extends Controller_App {
	
	public $view = 'templates/store';
	
	public $theme;
	
	public $menu_items; 
	
	public function before(){
		parent::before();
		
		$this->theme = $this->getStore()->getTheme()->name;
		
		$this->view->header = '';
		$this->view->content = '';
		$this->view->footer = '';
		
	}
	
	public function after(){
		$this->content = $this->view;
		
		$default_styles = array(URL::base() . 'media/themes/' . $this->theme . '/css/default.css' => 'screen');
		
		$this->styles = array_merge($this->styles, $default_styles);
		
		parent::after();
	}
	
	public function action_index(){
		$this->view->header = $this->getHeader();
	}
	
	public function action_products(){
		$this->view->header = $this->getHeader();	
	}
	
	public function action_contact(){
		$this->view->header = $this->getHeader();	
	}
	
	private function getHeader(){
		$header = new View('themes/' . $this->theme . '/header');
		$header->logo = $this->getStore()->title;
		$header->account_buttons = $this->getAccountItems();
		$header->menu_items = $this->getMenuItems();
		$header->store = $this->getStore();
		return $header;
	}
	
	private function getMenuItems(){
		return array(
			'home' => array('href' => $this->getURLStore(), 'name' => 'Index site.'),
			'products' => array('href' => $this->getURLStore('store/products'), 'name' => 'Products site.'),
			'contact' => array('href' => $this->getURLStore('store/contact'), 'name' => 'Contact form.'),
		);
	}
	
	private function getAccountItems(){
		return array(
			'my account' => array('href' => URL::site('/user/login_register'), 'name' => 'Log in or get an account.'),
			'my wishlist' => array('href' => URL::site('/user/login_register'), 'name' => 'Log in or get an account.'),
		);
	}
	
	protected function getStoreURL(){
		//Change with URL with subdomain.
		return URL::base() . '?store=' . $this->getStore()->name;
	}
}